import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *


class SliderDemo(QWidget):
    def __init__(self,parent=None):
        super(SliderDemo,self).__init__(parent)
        self.setWindowTitle("QSlider例子")
        self.resize(300,100)
        layout=QVBoxLayout()
        self.l1=QLabel("pyqt5")
        self.l1.setAlignment(Qt.AlignCenter)
        layout.addWidget(self.l1)
        #设置水平方向
        self.s1=QSlider(Qt.Horizontal)
        #设置最小值
        self.s1.setMinimum(5)
        #最大值
        self.s1.setMaximum(55)
        #步长
        self.s1.setSingleStep(3)
        #设置当前的值
        self.s1.setValue(10)
        #刻度位置
        self.s1.setTickPosition(QSlider.TicksBelow)
        #设置刻度间隔
        self.s1.setTickInterval(5)
        layout.addWidget(self.s1)
        #连接信号槽
        self.s1.valueChanged.connect(self.valuechange)
        self.setLayout(layout)
    def valuechange(self):
        print("current slider value=%s" %self.s1.value())




if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = SliderDemo()
    win.show()
    sys.exit(app.exec_())